//
//  FriendsViewController.m
//  一点互助
//
//  Created by rimi on 16/9/7.
//  Copyright © 2016年 zhangboqiu. All rights reserved.
//

#import "FriendsViewController.h"
#import "FTSearchBar.h"
#import "FriendsTableViewCell.h"
#import "FriendsTableViewHeader.h"


@interface FriendsViewController ()<UISearchBarDelegate,UITableViewDelegate,UITableViewDataSource,FriendsTableViewHeaderDelegate>
@property (strong, nonatomic) FTSearchBar *searchBar;
@property (strong, nonatomic) UITableView *tableView;
@property (assign, nonatomic) BOOL flag;
@property (strong, nonatomic) NSMutableArray *dataSource;
@property (strong, nonatomic) NSMutableArray *data;
@property (strong, nonatomic) FriendsTableViewHeader *header;
@end

@implementation FriendsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor colorWithRed:0.9123 green:0.9123 blue:0.9123 alpha:1.0]];
    self.flag = YES;
    [self.view addSubview:self.searchBar];
    [self.view addSubview:self.tableView];
    UINib *nib = [UINib nibWithNibName:@"FriendsTableViewCell" bundle:nil];
    [self.tableView registerNib:nib forCellReuseIdentifier:@"FriendsTableViewCell"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(FTSearchBar *)searchBar{
    if (!_searchBar) {
        _searchBar = [[FTSearchBar alloc]initWithFrame:CGRectMake(0, 80, kScreenWidth-40, 40*kScreenHeightScale)];
        _searchBar.center = CGPointMake(kScreenWidth/2, 100);
        _searchBar.delegate = self;
        _searchBar.backgroundColor = [UIColor whiteColor];
        _searchBar.layer.cornerRadius = 5;
    }
    return _searchBar;
}
-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.searchBar.frame)+CGRectGetMinY(self.searchBar.frame)-66, kScreenWidth, kScreenHeight-self.searchBar.frame.size.height) style:UITableViewStylePlain];
//        _tableView.backgroundColor = [UIColor grayColor];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (self.flag) {
        if (section == 0) {
            return 0;
        }else{
            return 10;
        }
    }else{
        if (section == 0) {
            return 10;
        }else{
            return 10;
        }
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    FriendsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FriendsTableViewCell" forIndexPath:indexPath];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80 * kScreenHeightScale;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        FriendsTableViewHeader *view = [FriendsTableViewHeader loadHeaderView];
        view.delegate = self;
        self.header = view;
        return self.header;
    }else{
        return nil;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 60;
    }else{
        return 0;
    }

}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 0) {
        return 20;
    }else{
        return 0;
    }
}
-(void)BtnTaped:(UIButton *)btn{
    self.flag = !self.flag;
    PLLOG(@"%c",self.flag);
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];


}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
